package com.linxiao.call.controller;

import com.alibaba.fastjson2.JSONObject;
import com.linxiao.call.domain.CrmCallBackCdr;
import com.linxiao.call.service.ICrmCallBackCdrService;
import com.linxiao.call.vo.QueryCrmCallBackCustomerInfoVO;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Objects;

/**
 * 回呼话单Controller
 *
 * @author qiqi
 * @date 2022-04-12
 */
@RestController
@RequestMapping("/crm/callBack/cdr")
public class CrmCallBackCdrController extends BaseController {
    @Autowired
    private ICrmCallBackCdrService crmCallBackCdrService;

    /**
     * 查询回呼话单列表
     */
    @GetMapping("/list")
    @Log(title = "【回呼通话记录列表】", businessType = BusinessType.LIST)
    public TableDataInfo list(CrmCallBackCdr crmCallBackCdr) {
        List<CrmCallBackCdr> list = crmCallBackCdrService.selectCrmCallBackCdrList(crmCallBackCdr);
        return getDataTable(list);
    }

    /**
     * 导出回呼话单列表
     */
    @Log(title = "【导出回呼通话记录列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCallBackCdr crmCallBackCdr) {
        List<CrmCallBackCdr> list = crmCallBackCdrService.selectCrmCallBackCdrList(crmCallBackCdr);
        ExcelUtil<CrmCallBackCdr> util = new ExcelUtil<>(CrmCallBackCdr.class);
        util.exportExcel(response, list, "回呼话单数据");
    }

    /**
     * 获取回呼话单详细信息
     */
    @GetMapping(value = "/detail")
    @Log(title = "【回呼通话记录详情", businessType = BusinessType.LIST)
    public AjaxResult getInfo(Long id,String cdrMainUniqueId) {
        return AjaxResult.success(crmCallBackCdrService.selectCrmCallBackCdrById(id,cdrMainUniqueId));
    }

    /**
     * 新增回呼话单
     */
    @PostMapping("/add")
    @Log(title = "【新增回呼话单】", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody CrmCallBackCdr crmCallBackCdr) {
        logger.info("新增回呼话单 crmCallBackCdr={}", JSONObject.toJSONString(crmCallBackCdr));
        if (Objects.isNull(crmCallBackCdr)) {
            return AjaxResult.error("新增回呼通话记录 实体参数不能为空");
        }
        return crmCallBackCdrService.insertCrmCallBackCdr(crmCallBackCdr);

    }
    
    /**
     * 查询回呼客户信息
     * @Title: getCallBackCustomerInfo
     * @Description: 
     * @param @param vo
     * @param @return 参数
     * @return AjaxResult 返回类型
     * @throws
     */
    @PostMapping("/getCallBackCustomerInfo")
    public AjaxResult getCallBackCustomerInfo(@RequestBody QueryCrmCallBackCustomerInfoVO vo){
    	return crmCallBackCdrService.getCallBackCustomerInfo(vo);
    }

}
